package jsyf.oa.dao.system;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.oa.entity.system.Enum2Entity;
import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public class Enum2Dao extends BaseDao {

    public Enum2Dao() {
        super.iBaseEntity = new Enum2Entity();
    }

    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
        return JSON.toJavaObject(json, Enum2Entity.class);
    }

    public Enum2Entity getById(String id) {
        return (Enum2Entity) super.getIBaseEntityById(id);
    }

    public Integer add(IBaseEntity entity) {
        entity.setId(super.generateKey());
        return super.insert(entity.getTableName(), entity.getJSONObject());
    }

    public List<JSONObject> getGroupBymoduleType() {
        String sql="SELECT t_sys_enum2.MODULE_TYPE as moduleType\n" +
                "FROM t_sys_enum2\n" +
                "WHERE 1=1 AND DEL_FLAG=0\n"+
                "GROUP BY t_sys_enum2.MODULE_TYPE\n";
        List<JSONObject> jsonList = super.queryForJsonList(sql, null);

        return jsonList;
    }
}
